# -*- coding: utf-8 -*-
"""
Created on Sat Nov 20 12:44:15 2021

@author: Administrator
"""

#引入：
import pygame as pg
import random 
from pygame.color import THECOLORS


#创建个类：
class AngryBirdClass(pg.sprite.Sprite):
    #初始化对象
    def __init__(self, image_file, location,speed):
        pygame.sprite.Sprite.__init__(self) 
        self.image = pg.image.load(image_file)
        #得到定义图像边界的矩形
        self.rect = self.image.get_rect()
        #小鸟的初始位置
        self.rect.left,self.rect.top = location
        #创建速度属性
        self.speed = speed
    #增加运动方法    
    def move(self):
        self.rect = self.rect.move(self.speed)
        #检测是否达到窗口边界
        if self.rect.left < 0 or self.rect.right > width:
            self.speed[0] = -self.speed[0]
        if self.rect.top < 0 or self.rect.bottom > height:
            self.speed[1] = -self.speed[1]
            

#设置窗口大小、颜色、载入图片        
size = width,height = 800,600
screen = pg.display.set_mode(size)
screen.fill(THECOLORS['white'])
red_img = './pic/horse_1.png'
blue_img = './pic/blueBird.png'


#创建一个小鸟列表
birds = []
for row in range(0,4):
    #每次循环都有一个不同的位置
#        location = [column*180+10,row*180+10]
    location = [10,row*80]
    #速度随机
    speed = [random.randint(1,5)+random.randint(1,5)*0.2,0]
    bird = AngryBirdClass(red_img,location,speed)
    #将各个小鸟添加到列表中
    birds.append(bird)

for row in range(0,4):
    #每次循环都有一个不同的位置
#        location = [column*400+100,row*360+100]
    location = [10,row*80+320]
    #速度随机
    speed = [random.randint(1,5)+random.randint(1,5)*0.2,0]
    bird = AngryBirdClass(blue_img,location,speed)
    #将各个小鸟添加到列表中
    birds.append(bird)
#主循环
mRunning = True
while mRunning:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            mRunning = False
    #时间延迟
    pygame.time.delay(20)
    screen.fill(THECOLORS['white'])
    for bird in birds:
        bird.move()
        screen.blit(bird.image,bird.rect)
    pg.display.flip()
pg.quit()